<%@ page language="java" import="java.util.*,com.beans.*,com.dao.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";            
%>
<!DOCTYPE html>  
<html>
  <head>
     <base href="<%=basePath%>">    
    <title>一级分类维护</title>   
	<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
	<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
	<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
	<script type="text/javascript"  src="js/validate.js"></script>
	<script>		
		$(function(){
			 $("input[type=text],textarea").focus(function(){
				  $(this).addClass("input_focus");
				}).blur(function(){
						$(this).removeClass("input_focus");
				});

			$(".form_btn").hover(function(){
					$(this).css("color","red").css("background","#6FB2DB");
				},
				
				function(){
					$(this).css("color","#295568").css("background","#BAD9E3");
				});
				
				
			//重置按钮被点击,要清除原来的页面信息
		    $(":reset").click(function(){
		    	showInfo(document.getElementById("cateName"),'长度 4-20 位');
		    	$("#result_msg").html("");
		    });
		    
		   
		});
		
		
		//验证分类名
		function validateCateName(item){
		
			var result=true;
			var reg=/^\S{2,20}$/;   //2-20个合法字符(非空白)
			if(!reg.test(item.value)){
				result=false;
				showError(item,"分类名格式不正确");
			}	

			if(result==true){
				showOk(item);
			}
			return result;	
		}

		//总验证
		function validateInput(){
			$("#result_msg").html("");  //清除原来的验证信息
			var result=true;
			
			if(validateCateName(document.getElementById("cateName"))==false){
				result=false;
			}
			
			if(result==true){
				result=confirm('确定提交吗');
			}
			
			return result;
			
		}
 	</script>
  </head>
  
  <body>
  		 <%
  			//查询所有一级分类,构成一级分类下拉框 
  			int cateId=Integer.parseInt(request.getParameter("id"));
  			CateInfo  cateInfo=new CateDao().getCateInfoById(cateId);
  			request.setAttribute("cateInfo",cateInfo);
  		 %>
  		 
     <div class ="div_title">
		 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>商品管理    一级分类维护</span></div>
	 </div>
				 
	 <form action="CateServlet.do" method="post"  onsubmit="return validateInput()">
	 	<input type="hidden" name="flag" value="updatecate" />
	 	<input type="hidden" name="id" value="${cateInfo.id }" />
		 <table class="edit_table" >

		 		<tr>
		 			 	<td class="td_info">分类名称:</td>	
		 			 	<td class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="cateName" name="cateName" 
		 			 			onfocus="showInfo(this,'长度 2-20 位')" 
		 			 			onblur="validateCateName(this)"
		 			 			value="${cateInfo.cateName }"
		 			 		/> 
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="cateName_msg">长度 2-20 位非空白字符</label>
		 			 	</td> 
		 		</tr>
		 		
		 		


		 		<tr>
		 			<td class="td_info">分类描述:</td>	
		 			<td><textarea rows="4" cols="27" name="des" class="txtarea">${cateInfo.des}</textarea> </td>	
		 			<td><label></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td> 
		 			<input class="form_btn" type="submit" value="保存修改" /> 
		 		
		 			<td>
		 				<label id="result_msg" class="result_msg">${msg}</label>
		 			</td>	
		 		</tr>
		</table>
     </form>
  </body>
</html>
